package com.wulis.common.wrapper;

import org.apache.commons.lang3.StringUtils;

import com.wulis.common.model.enums.HttpStatusEnum;

import io.swagger.annotations.ApiModel;

/**
 * @author wulis
 */
@ApiModel(description ="返回通用类")
public class ApiWrapMapper {
    
    private ApiWrapMapper() {
    }
    
    public static <E> ApiWrapper<E> illegalParameter() {
        return wrap(HttpStatusEnum.ILLEGAL_ARGUMENT.code(), HttpStatusEnum.ILLEGAL_ARGUMENT.message());
    }
    
    public static <E> ApiWrapper<E> illegalParameter(String message) {
        return wrap(HttpStatusEnum.ILLEGAL_ARGUMENT.code(),
            StringUtils.isBlank(message) ? HttpStatusEnum.ILLEGAL_ARGUMENT.message() : message);
    }
    
    public static <E> ApiWrapper<E> error() {
        return wrap(HttpStatusEnum.ERROR.code(), HttpStatusEnum.ERROR.message());
    }
    
    public static <E> ApiWrapper<E> error(String message) {
        return wrap(HttpStatusEnum.ERROR.code(),
            StringUtils.isBlank(message) ? HttpStatusEnum.ERROR.message() : message);
    }
    
    public static <E> ApiWrapper<E> success() {
        return wrap(HttpStatusEnum.SUCCESS.code(), HttpStatusEnum.SUCCESS.message());
    }
    
    public static <E> ApiWrapper<E> success(E o) {
        return wrap(HttpStatusEnum.SUCCESS.code(), HttpStatusEnum.SUCCESS.message(), o);
    }
    
    public static <E> ApiWrapper<E> wrap(int code, String message, E o) {
        return new ApiWrapper<>(code, message, o);
    }
    
    public static <E> ApiWrapper<E> wrap(int code, String message) {
        return wrap(code, message, null);
    }
    
    public static <E> ApiWrapper<E> wrap(HttpStatusEnum httpStatusEnum) {
        return wrap(httpStatusEnum.code(), httpStatusEnum.message(), null);
    }
}
